package cn.linjianhui.interview.thread;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.concurrent.CountDownLatch;

public class CountDownTest {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(2);
        new Thread("子线程1"){public void run() {
            try {
                System.out.println(Thread.currentThread().getName() + "正在执行");
                Thread.sleep(3000);
                System.out.println(Thread.currentThread().getName() + "执行完毕");
                latch.countDown();
            }catch (Exception e) {

            }
        }}.start();

        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\test.pdf"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

        new Thread("子线程2"){public void run() {
            try {
                System.out.println(Thread.currentThread().getName() + "正在执行");
                Thread.sleep(3000);
                System.out.println(Thread.currentThread().getName() + "执行完毕");
                latch.countDown();
            } catch (Exception e) {

            }
        }}.start();

        try {
            latch.await();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
